#include "worker.h"

Worker::Worker()
{

}

Worker::Worker(Capture* cap, Receiver* receiver)
{
    setCapture(cap);
    addReceiver(receiver);
}

void Worker::setCapture(Capture* capture)
{
    this->cap = capture;
}

void Worker::addReceiver(Receiver* receiver)
{
    receivers.push_back(receiver);
}

void Worker::run()
{
    if(!cap || receivers.empty()) {
        return;
    }

    while(true) {
        cv::Mat frame;
        frame = cap->getNextFrame();

        if(!frame.empty()) {
            for(std::vector<Receiver*>::iterator\
                it=receivers.begin();\
                it!=receivers.end();\
                ++it) {
                (*it)->newFrame(frame);
            }
        }

        msleep(50);
    }
}

Worker::~Worker()
{
}
